/**
 * Created by GeYingJie on 2022/08/12.
 */
const ExtsSpreadsheet = {
  "xls": "xls",
  "xlsx": "xlsx",
  "xlsm": "xlsm",
  "xlt": "xlt",
  "xltx": "xltx",
  "xltm": "xltm",
  "ods": "ods",
  "fods": "fods",
  "ots": "ots",
  "csv": "csv"
};

const ExtsPresentation = {
  "pps":"pps",
  "ppsx":"ppsx",
  "ppsm":"ppsm",
  "ppt":"ppt",
  "pptx":"pptx",
  "pptm":"pptm",
  "pot":"pot",
  "potx":"potx",
  "potm":"potm",
  "odp":"odp",
  "fodp":"fodp",
  "otp":"otp"
};

const ExtsDocument = {
  "doc": "doc",
  "docx":"docx",
  "docm": "docm",
  "dot":"dot",
  "dotx":"dotx",
  "dotm":"dotm",
  "odt":"odt",
  "fodt":"fodt",
  "ott":"ott",
  "rtf":"rtf",
  // "txt":"txt",
  "html":"html",
  "htm":"htm",
  "mht":"mht",
  "pdf":"pdf",
  "fb2":"fb2",
  "epub":"epub",
  "xps":"xps"
};

/**
 * 
 * @param {string} filename 
 * @returns {resolve || reject}
 */
function GetEditorType(filename) {
  return new Promise((resolve, reject) => {
    var nIndex = filename ? filename.lastIndexOf(".") : -1;
    if (nIndex !== -1) {
      var filetype = filename.substring(nIndex + 1).toLowerCase();
      if (ExtsDocument[filetype]) resolve("document");
      if (ExtsSpreadsheet[filetype]) resolve("spreadsheet");
      if (ExtsPresentation[filetype]) resolve("presentation");
      reject();
    } else {
      reject();
    }
  });
}